<?php

namespace app\common\model\mysql;

use think\Model;

class SysRoleMenu extends Model
{
    //批量插入角色与菜单关联表数据
    public function insertAllRoleMenu($menuIds,$roleId){
        // 构造批量插入的数据数组
        $data = [];
        foreach ($menuIds as $menuId) {
            $data[] = [
                'role_id' => $roleId,
                'menu_id' => $menuId,
            ];
        }
        return $this->insertAll($data);
    }

    //删除角色与菜单关联表数据
    public function deleteAllRoleMenu($roleId){
        if(empty($roleId)){
            return false;
        }
        $where = [
            "role_id" =>$roleId,
        ];
        return $this->where($where)->delete();
    }

    //根据角色ID查询菜单下拉树结构
    public function getRoleMenuIdArray($roleId){
        if(empty($roleId)){
            return false;
        }
        $where = [
            "role_id" =>$roleId,
        ];
        $result = $this->where($where)->column('menu_id');
        return $result;
    }


    public function getRoleMenuInIdArray($roleIds){
        if(empty($roleIds)){
            return false;
        }
        $where = [
            ['role_id','in',$roleIds]
        ];
        $result = $this->where($where)->column('menu_id');
        return $result;
    }
}
